package com.bazaaroid.server.gae.core.dto.partner;

import java.util.ArrayList;
import java.util.List;

import javax.xml.bind.annotation.XmlElement;
import javax.xml.bind.annotation.XmlRootElement;

import com.bazaaroid.server.gae.core.dto.UserDTO;
import com.bazaaroid.server.gae.core.persistence.model.User;
import com.bazaaroid.server.gae.core.persistence.model.partner.Category;
import com.bazaaroid.server.gae.core.persistence.model.partner.Discount;
import com.bazaaroid.server.gae.core.persistence.model.partner.Location;
import com.bazaaroid.server.gae.core.persistence.model.partner.Partner;
import com.bazaaroid.server.gae.core.persistence.model.partner.Product;
import com.bazaaroid.server.gae.core.persistence.model.partner.Tag;

@XmlRootElement(name = "AllEntities")
public class AllEntitiesDTO {
	private List<Partner> allPartners = null;
	private List<Location> allLocations = null;
	private List<Product> allProducts = null;
	private List<Discount> allDiscounts = null;
	private List<Category> allCategories = null;
	private List<Tag> allTags = null;
	private List<User> allUsers = null;

	public AllEntitiesDTO() {}

	public AllEntitiesDTO(List<Partner> partners, List<Location> locations,
			List<Product> products, List<Discount> discounts,
			List<Category> categories, List<Tag> tags, List<User> users) {
		this.allPartners = partners;
		this.allLocations = locations;
		this.allProducts = products;
		this.allDiscounts = discounts;
		this.allCategories = categories;
		this.allTags = tags;
		this.allUsers = users;
	}

	@XmlRootElement(name = "partners")
	public static class PartnersDTO {
		List<Partner> partners = null;

		public PartnersDTO() {}

		public PartnersDTO(List<Partner> partners) {
			this.partners = partners;
		}

		@XmlElement(name = "partner")
		public List<PartnerDTO> getPartners() {
			List<PartnerDTO> partnersDTO = new ArrayList<PartnerDTO>();
			for(Partner partner: partners)
				partnersDTO.add(new PartnerDTO(partner));

			return partnersDTO;
		}
	}

	@XmlRootElement(name = "locations")
	public static class LocationsDTO {
		List<Location> locations = null;

		public LocationsDTO() {}

		public LocationsDTO(List<Location> locations) {
			this.locations = locations;
		}

		@XmlElement(name = "location")
		public List<LocationDTO> getLocations() {
			List<LocationDTO> locationsDTO = new ArrayList<LocationDTO>();
			for(Location location: locations)
				locationsDTO.add(new LocationDTO(location));

			return locationsDTO;
		}
	}

	@XmlRootElement(name = "products")
	public static class ProductsDTO {
		List<Product> products = null;

		public ProductsDTO() {}

		public ProductsDTO(List<Product> products) {
			this.products = products;
		}

		@XmlElement(name = "product")
		public List<ProductDTO> getProducts() {
			List<ProductDTO> productsDTO = new ArrayList<ProductDTO>();
			for(Product product: products)
				productsDTO.add(new ProductDTO(product));

			return productsDTO;
		}
	}

	@XmlRootElement(name = "discounts")
	public static class DiscountsDTO {
		List<Discount> discounts = null;

		public DiscountsDTO() {}

		public DiscountsDTO(List<Discount> discounts) {
			this.discounts = discounts;
		}

		@XmlElement(name = "discount")
		public List<DiscountDTO> getDiscounts() {
			List<DiscountDTO> discountsDTO = new ArrayList<DiscountDTO>();
			for(Discount discount: discounts)
				discountsDTO.add(new DiscountDTO(discount));

			return discountsDTO;
		}
	}

	@XmlRootElement(name = "categories")
	public static class CategoriesDTO {
		List<Category> categories = null;

		public CategoriesDTO() {}

		public CategoriesDTO(List<Category> categories) {
			this.categories = categories;
		}

		@XmlElement(name = "category")
		public List<CategoryDTO> getCategories() {
			List<CategoryDTO> categoriesDTO = new ArrayList<CategoryDTO>();
			for(Category category: categories)
				categoriesDTO.add(new CategoryDTO(category));

			return categoriesDTO;
		}
	}

	@XmlRootElement(name = "tags")
	public static class TagsDTO {
		List<Tag> tags = null;

		public TagsDTO() {}

		public TagsDTO(List<Tag> tags) {
			this.tags = tags;
		}

		@XmlElement(name = "tag")
		public List<TagDTO> getTags() {
			List<TagDTO> tagsDTO = new ArrayList<TagDTO>();
			for(Tag tag: tags)
				tagsDTO.add(new TagDTO(tag));

			return tagsDTO;
		}
	}

	@XmlRootElement(name = "users")
	public static class UsersDTO {
		List<User> users = null;

		public UsersDTO() {}

		public UsersDTO(List<User> users) {
			this.users = users;
		}

		@XmlElement(name = "user")
		public List<UserDTO> getUsers() {
			List<UserDTO> usersDTO = new ArrayList<UserDTO>();
			for(User user: users)
				usersDTO.add(new UserDTO(user));

			return usersDTO;
		}
	}

	@XmlElement(name = "partners")
	public PartnersDTO getAllPartners() {
		return new PartnersDTO(allPartners);
	}

	@XmlElement(name = "locations")
	public LocationsDTO getLocations() {
		return new LocationsDTO(allLocations);
	}

	@XmlElement(name = "products")
	public ProductsDTO getAllProducts() {
		return new ProductsDTO(allProducts);
	}

	@XmlElement(name = "discounts")
	public DiscountsDTO getDiscounts() {
		return new DiscountsDTO(allDiscounts);
	}

	@XmlElement(name = "categories")
	public CategoriesDTO getCategories() {
		return new CategoriesDTO(allCategories);
	}

	@XmlElement(name = "tags")
	public TagsDTO getTags() {
		return new TagsDTO(allTags);
	}

	@XmlElement(name = "users")
	public UsersDTO getUsers() {
		return new UsersDTO(allUsers);
	}
}
